package cn.edu.nbpt.campus_api.controller.campus;

import cn.edu.nbpt.campus_api.model.campus.file.FileTypeEnum;
import cn.edu.nbpt.campus_api.model.Result;
import cn.edu.nbpt.campus_api.service.campus.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("campus/file")
public class FileController {

    @Resource
    private FileService fileService;

    @PostMapping("upload")
    public Result<String> upload(MultipartFile file) {
        return Result.success(fileService.upload(file));
    }

    @GetMapping("download/{fileName}/{fileType}")
    public void download
            (@PathVariable String fileName,
             @PathVariable FileTypeEnum fileType,
             HttpServletResponse response) {

        fileService.download(fileName, fileType, response);
    }
}
